package com.gk.controller.api;

import com.alibaba.fastjson2.JSON;
import com.eight.pojo.UserCharge;
import com.eight.util.QRCodeUtil;
import com.eight.vo.ComResult;
import com.gk.service.UserChargeService;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

 /**
 * 用户优惠卷控制层
 * @Description: TODO
 * @Author: Van.Planifolia
 * @CreateTime: 2023-03-03  18:13
 * @Version: 1.0
 */
@RestController
public class UserChargeApi {
    @Resource
    private UserChargeService userChargeService;

    /**
     * 根据当前登录的用户信息来进行查询用户重置记录
     * @return 查询的信息
     */
    @GetMapping("/customer/api/charge/{pageIndex}/{pageSize}")
    public ComResult getCharge(@PathVariable Integer pageIndex, @PathVariable Integer pageSize){
        return userChargeService.getUserCharge(pageIndex,pageSize);
    }

    /**
     * 生产指定id的充值账单二维码
     * @param id 充值账单id
     * @return 查询的结果
     */
    @GetMapping("/customer/api/charge/getById/{id}")
    public ComResult generateChargeQcCode(@PathVariable Integer id){
        UserCharge userCharge = userChargeService.getById(id);
        String s1 = QRCodeUtil.generateBase64(QRCodeUtil.produceImage(JSON.toJSONString(userCharge)));
        return new ComResult(2000,"生成成功",s1);
    }


    /**
     * 根据id查询状态
     * @param id
     * @return
     */
    @PostMapping("/customer/api/charge/getPayStatusTwo/{id}")
    public ComResult getPayStatusTwo(@PathVariable Integer id){
        UserCharge userCharge = userChargeService.selectOneUserCharge(id);
        return userChargeService.getPayStatus(userCharge.getSerilcode());
    }

     /**
      * 根据id查询状态
      * @param id
      * @return
      */
     @GetMapping ("/customer/api/charge/getPayStatus/{id}")
     public ComResult getPayStatus(@PathVariable String id){
         return userChargeService.getPayStatus(id);
     }
    /**
     * 根据id查询账单单号
     * @param id id
     * @return 账单信息
     */
    @PostMapping("/customer/api/charge/getPayStatus/{id}")
    public UserCharge selectOneUserCharge(@PathVariable Integer id){
      return   userChargeService.selectOneUserCharge(id);
    }


     /**
      * 取消订单，修改订单状态
      * @param id 订单序号
      * @return 1
      */
     @PostMapping("/customer/api/charge/setPaystatus/{id}")
     public ComResult setPayStatus(@PathVariable Integer id){
         return userChargeService.setPayStatus(id);
     }


}
